package com.yun.algorithmproblem.leetcode;

public class Leetcode121_SharesI {
    public int maxProfit(int[] prices) {
        int i = 0;
        int j = 1;
        int max = 0;
        while (j < prices.length) {
            if (prices[j] - prices[i] > 0) {
                max = Math.max(max, prices[j] - prices[i]);
            } else {
                i = j;
            }
            j++;
        }
        return max;
    }

    public static void main(String[] args) {
        int[] prices = {7, 1, 5, 3, 6, 4};
        int[] prices2 = {3, 3};
        Leetcode121_SharesI test = new Leetcode121_SharesI();
        System.out.println(test.maxProfit(prices));
    }
}
